#ifndef POPUPITEMMODEL_H
#define POPUPITEMMODEL_H

#include <QAbstractItemModel>
#include <QMovie>

#include "MessageData.h"

class PopupItemModel :public QAbstractItemModel
{
    Q_OBJECT

public:
    PopupItemModel();

    // 构造父节点下子节点的索引
    virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
    // 通过子节点索引获取父节点索引
    virtual QModelIndex parent(const QModelIndex &child) const override;

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;

    // 获取节点数据：包括DisplayRole|TextAlignmentRole等
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    void push(const QPixmap &avatar, const QString &name, const QString &text);

    void updateData(int index,const QString &text);

    void push(MessageData &data);/* 如果有id，则数字加1并展示 */

    /**
     * @brief removeRow
     * @param row 下标从1开始
     * @param parent
     * @return
     */
    bool removeRow(int row, const QModelIndex &parent = QModelIndex());

    /**
     * @brief setGifRange 更新视图范围，用来控制movie的启动性能
     * @param begin
     * @param end
     */
    void setGifRange(int begin, int end);

private:
    QList<MessageData> m_data;
};

#endif // POPUPITEMMODEL_H
